<!--
<template>
  &lt;!&ndash; 添加或修改项目采购信息管理对话框 &ndash;&gt;
  <el-dialog :title="title" :visible.sync="open" width="80%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
      <el-tabs v-model="activeName" class="detail-tab" type="card">
        <el-tab-pane label="基本信息" name="first">
          <el-row :gutter="20">
            &lt;!&ndash;<el-col :span="12">
              <el-form-item label="项目id" prop="projectId">
                <el-input v-model="form.projectId" placeholder="请输入项目id"/>
              </el-form-item>
            </el-col>&ndash;&gt;
            <el-col :span="24">
              <el-form-item label="项目名称" prop="projectName">
                <el-input v-model="form.projectName" placeholder="请输入项目名称" disabled/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="商品名称" prop="name">
                <el-input v-model="form.name" placeholder="请输入商品名称" style="width: 300px"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="商品品牌" prop="brand">
                <el-input v-model="form.brand" placeholder="请输入商品品牌" style="width: 200px"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="商品单价" prop="unitCost">
                <el-input-number :precision="2" v-model="form.unitCost" placeholder="请输入商品单价" @change="updateTotleCostPrj()"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购数量" prop="count">
                <el-input-number v-model="form.count" placeholder="请输入采购数量" @change="updateTotleCostPrj()"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="采购总价" prop="totleCost">
                <el-input-number :precision="2" v-model="form.totleCost" placeholder="请输入采购总价"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="价格是否含税" prop="taxFlag">
                <el-select v-model="form.taxFlag" placeholder="请选择价格是否含税" clearable style="width: 200px" @change="updateTaxTotleCost">
                  <el-option v-for="dict in dict.type.yes_no"
                             :key="dict.value" :label="dict.label" :value="dict.value"/>
                </el-select>
&lt;!&ndash;                <el-input v-model="form.taxFlag" placeholder="请选择价格是否含税"/>&ndash;&gt;
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="含税总价" prop="taxTotleCost">
                <el-input-number :precision="2" v-model="form.taxTotleCost" placeholder="请输入含税总价"/>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="商品单位" prop="unit">
                <el-input v-model="form.unit" placeholder="请输入商品单位" style="width: 200px"/>
              </el-form-item>
            </el-col>
            &lt;!&ndash;<el-col :span="12">
              <el-form-item label="采购人" prop="buyId">
                <el-select v-model="form.buyId" placeholder="请选择采购人" @change="selectUserForPrjOrder" clearable style="width: 200px">
                  <el-option v-for="dict in dict.type.sys_user" ref="myselectUserForPrjOrder"
                             :key="dict.value" :label="dict.label" :value="dict.value"/>
                </el-select>
              </el-form-item>
            </el-col>&ndash;&gt;
            <el-col :span="12">
              <el-form-item label="采购日期" prop="buyDate">
                <el-date-picker clearable
                                v-model="form.buyDate"
                                type="date"
                                value-format="yyyy-MM-dd"
                                placeholder="请选择采购日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="备注信息" prop="infomation">
                <el-input v-model="form.infomation" type="textarea" placeholder="请输入内容"/>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
    import {addAction, getById, updateAction} from '@/api/manage'

    export default {
        name: "ProjectOrderInfoForm",
        dicts: [ "yes_no"],
        data() {
            return {
                // 遮罩层
                loading: true,
                activeName: "first",
                // 弹出层标题
                title: "",
                // 是否显示弹出层
                open: false,
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                    name: [
                        {required: true, message: "商品名称不能为空", trigger: "blur"}
                    ],
                    brand: [
                        {required: true, message: "商品品牌不能为空", trigger: "blur"}
                    ],
                },
                url: {
                    getById: '/projectOrderInfo/projectOrderInfo/',
                    add: '/projectOrderInfo/projectOrderInfo/add',
                    edit: '/projectOrderInfo/projectOrderInfo/edit',
                },
                companyName: "",
            };
        },
        created() {

        },
        methods: {
            updateTaxTotleCost(){
                let that = this;
                let percent = 1;
                if (that.form.totleCost && that.form.taxFlag) {
                    if(that.form.taxFlag === "0"){
                        if(that.companyName == "1"){
                            percent = 1.15;
                        }else{
                            percent = 1;
                        }
                    }else{
                        percent = 1;
                    }
                    let taxTotleCost = that.functionNumberMul(that.form.totleCost, percent);
                    that.$set(that.form, "taxTotleCost", taxTotleCost);
                }
            },
            updateTotleCostPrj(){
                let that = this;
                if (that.form.count && that.form.unitCost) {
                    let totleCost = that.functionNumberMul(that.form.count, that.form.unitCost);
                    that.$set(that.form, "totleCost", totleCost);
                    that.updateTaxTotleCost();
                }
            },
            functionNumberMul(arg1, arg2) {
                var m = 0;
                var s1 = arg1.toString();
                var s2 = arg2.toString();
                try {
                    m += s1.split(".")[1].length;
                } catch (e) {
                }
                try {
                    m += s2.split(".")[1].length;
                } catch (e) {
                }
                let c1 = Number(s1.replace(".", ""));
                let c2 = Number(s2.replace(".", ""));
                let c3 = Math.pow(10, m);
                return c1  *  c2 / c3;
            },
            selectUserForPrjOrder(value) {
                let that = this;
                that.$nextTick(() => {
                    let arr = that.$refs.myselectUserForPrjOrder;
                    for (let i = 0; i < arr.length; i++) {
                        if (arr[i].currentValue == value) {
                            that.form.buyName = arr[i].label;
                        }
                    }
                })
                // console.log(that.form.buyName);
            },
            handleAddNew(data) {
                let that = this;
                that.reset();
                that.open = true;
                that.form.projectId = data.projectId;
                that.form.projectName = data.projectName;
                that.companyName = data.companyName;
                that.title = "添加项目采购信息";
            },
            // 取消按钮
            cancel() {
                this.open = false;
                this.reset();
            },
            // 表单重置
            reset() {
                this.form = {
                    id: null,
                    delFlag: null,
                    createBy: null,
                    createTime: null,
                    updateBy: null,
                    updateTime: null,
                    remark: null,
                    name: null,
                    brand: null,
                    unitCost: null,
                    count: null,
                    unit: null,
                    totleCost: null,
                    buyId: null,
                    buyName: null,
                    buyDate: null,
                    projectId: null,
                    projectName: null,
                    taxFlag: null,
                    taxTotleCost: null
                };
                this.resetForm("form");
            },
            /** 新增按钮操作 */
            handleAdd() {
                this.reset();
                this.open = true;
                this.title = "添加项目采购信息";
            },
            /** 修改按钮操作 */
            handleUpdate(row) {
                this.companyName = row.companyName;
                this.reset();
                const id = row.id || this.ids;
                getById(this.url.getById, id).then(response => {
                    this.form = response.data;
                    this.open = true;
                    this.title = "修改项目采购信息";
                });
            },
            /** 提交按钮 */
            submitForm() {
                this.$refs["form"].validate(valid => {
                    if (valid) {
                        if (this.form.id != null) {
                            updateAction(this.url.edit, this.form).then(response => {
                                this.$modal.msgSuccess("修改成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        } else {
                            addAction(this.url.add, this.form).then(response => {
                                this.$modal.msgSuccess("新增成功");
                                this.open = false;
                                this.$emit('ok');
                            });
                        }
                    }
                });
            },
        }
    };
</script>
-->
